package com.virus.coronavirus.controller;

import com.virus.coronavirus.error.SystemException;
import com.virus.coronavirus.model.Area;
import com.virus.coronavirus.model.User;
import com.virus.coronavirus.model.vo.AreaEditVO;
import com.virus.coronavirus.model.vo.AreaVO;
import com.virus.coronavirus.response.ControllerEndpoint;
import com.virus.coronavirus.response.ResponseBean;
import com.virus.coronavirus.service.AreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: Bbeginner
 * @Date: 2021/2/5 18:51
 * @Version 1.0
 **/
@RestController
@RequestMapping("/virus/area")
@Validated
@Api(tags = "疫情防控模块-区域相关接口")
public class AreaController {

    @Autowired
    private AreaService areaService;

    /**
     * 添加区域信息
     * @param areaVO
     * @return
     */
    @ControllerEndpoint(exceptionMessage = "添加区域失败", operation = "添加区域")
    @ApiOperation(value = "添加区域", notes = "添加区域信息")
    @RequiresPermissions({"area:add"})
    @PostMapping("/add")
    public ResponseBean add(@RequestBody @Validated AreaVO areaVO) throws SystemException {
        areaService.add(areaVO);
        return ResponseBean.success();
    }

    /**
     * 删除区域信息
     *
     * @param placename 风险区名
     * @return
     */
    @ControllerEndpoint(exceptionMessage = "删除区域失败", operation = "删除区域")
    @RequiresPermissions({"area:delete"})
    @ApiOperation(value = "删除区域", notes = "删除区域信息，根据风险区名")
    @DeleteMapping("/delete/{placename}")
    public ResponseBean delete(@PathVariable String placename) throws SystemException {
        areaService.deleteByPlace(placename);
        return ResponseBean.success();
    }



    // 更新风险区域
    @ControllerEndpoint(exceptionMessage = "更新区域失败", operation = "更新区域:输入字符串，注意前两个分别是clat和clng")
    @ApiOperation(value = "更新区域", notes = "更新区域信息")
    @RequiresPermissions({"area:update"})
    @PostMapping("/update/{placename}")
    public ResponseBean update(@PathVariable String placename, String boundary)throws SystemException{
        areaService.update(placename,boundary);
        return ResponseBean.success();
    }


//    /**
//     * 根据经纬度查找某范围内的中高风险地区
//     * @param range,lng1,lng2,lng3,lat1,lat2,lat3
//     */
//    @ApiOperation(value = "查询某范围内风险区域", notes = "根据经纬度查找某范围内的中高风险地区")
//    @GetMapping("/arearange/{range}")
//    public ResponseBean selectAreaBylatlng(@PathVariable Double range, Double lng1, Double lat1,Double lng2, Double lat2,Double lng3, Double lat3) throws SystemException {
//        List<Area> arearange = areaService.selectAreaBylatlng(range,lng1,lng2,lng3,lat1,lat2,lat3);
//        return ResponseBean.success(arearange);
//    }










    /**
     * 查找风险区域
     * @param id
     */
    @ApiOperation(value = "通过ID查询风险区域", notes = "查询风险区域,根据ID")
    @GetMapping("/areaid/{id}")
    public ResponseBean findareabyid(@PathVariable Long id) throws SystemException {
        String areaById = areaService.findAreaById(id);
        return ResponseBean.success(areaById);
    }

    /**
     * 不必输入全部的地区名字,可以自动匹配(如果数据库字段中包含所输入的信息)
     * @param name
     */
    @ApiOperation(value = "通过地区名查询风险区域", notes = "查看编辑")
    @GetMapping("/oneareaname/{name}")
    public ResponseBean findoneareabyname(String name) throws SystemException {
        String areabyname = areaService.findoneAreabyname(name);
        return ResponseBean.success(areabyname);
    }
    /*一个*/
    /**
     * 不必输入全部的地区名字,可以自动匹配(如果数据库字段中包含所输入的信息)
     * @param name
     */
    @ApiOperation(value = "察看地区名查询区域", notes = "查询风险区域,根据地区名")
    @GetMapping("/areanames/{word}")
    public ResponseBean findareasbyname(String word) throws SystemException {
        List<Area> areas = areaService.findAreasbyword(word);
        return ResponseBean.success(areas);
    }
    /*一个*/

}
